﻿<?xml version="1.0" encoding="utf-8" ?>
<DNJTemplate>
		<HEADER>
			<![CDATA[
/*
This is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.

This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this software; if not, write to the Free
Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
/*
DNJRPC Plugin script template 
*/			
function DNJDebug(msg)
{   
    if (window.console && window.console.log) console.log("DNJ DBG :: %s", msg);
    else alert(msg);
}

(function (jQuery){
	jQuery.DNJRPC = function(options){
	var settings = 
	    {
	        success: null
	    };
	var EObj = this;    
	var jsoncount = 1;
	if(options) { $.extend(settings, options);}
    function SuccessCB(data){
                if (typeof(settings.success) == 'function') 
                    return settings.success(data);
    };

    
    function DNJCall(function_name, _arguments)
    {              
        var jsondata = {method:function_name, params:new Array(), id:jsoncount};
        jsoncount++;
        var args='';        
        for (var i = 0; i < _arguments.length; i++)
            jsondata.params.push(_arguments[i]);
               
        $.post('DNJUndefinedInvoker', jsondata, SuccessCB, 'json');
        
            
    };
    function FnFactory(name, Pack)    
    {
        pname = "EObj";
        tokens = Pack.split('.');                     
        expression = '';
        for (var i = 0; i<tokens.length; i++)
        {
            pname += '.' + tokens[i];     
            expression += 'if (!'+pname+')' + pname+' = new Object();'
        }        
        expression += pname+'.'+name+' = EObj.'+name+' = function() {DNJCall("'+name+'", arguments)};'        
        return expression;        
    }
    var dynCode = '';
			
			]]>
		</HEADER>
		<FACTORY_LOOP>
			<![CDATA[
			dynCode += FnFactory('DNJUndefinedSub', 'DNJUndefinedPackage');
			]]>			
		</FACTORY_LOOP>
		<MAPPING_ERROR>
			<![CDATA[
			DNJDebug("unable to load mapping file : DNJMAPPING");
			]]>
		</MAPPING_ERROR>
		<FOOTER>
			<![CDATA[
    eval(dynCode);
    return jQuery;}
})(jQuery);			
			]]>
		</FOOTER>
</DNJTemplate>
